package com.ruicar.afs.cloud.apply.archive.controller;

import com.ruicar.afs.cloud.apply.archive.condition.DelayMngCondition;
import com.ruicar.afs.cloud.apply.archive.service.DelayMngService;
import com.ruicar.afs.cloud.archive.dto.DelayDto;
import com.ruicar.afs.cloud.archive.result.ArchiveDocListDto.ArchivedDocDetail;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 延期管理controller
 *
 * @author 耿继辉
 */
@RestController
@AllArgsConstructor
@Slf4j
@Api(value = "delay", description = "延期管理")
@RequestMapping("/delay")
public class DelayMngController {

    private final DelayMngService delayMngService;

    @PostMapping("/getDelayList")
    public IResponse getDelayList(@RequestBody QueryCondition<DelayMngCondition> condition) {
        DelayDto delayDto = new DelayDto();
        delayDto.setKey(condition.getCondition().getKey());
        delayDto.setPageIndex(condition.getCondition().getPageNumber());
        delayDto.setPageSize(condition.getCondition().getPageSize());
        delayDto.setDelayDays(condition.getCondition().getDelayDays());
        delayDto.setStartAppDate(condition.getCondition().getAppDate().length>0?condition.getCondition().getAppDate()[0]:null);
        delayDto.setEndAppDate(condition.getCondition().getAppDate().length>0?condition.getCondition().getAppDate()[1]:null);
        delayDto.setStatus(condition.getCondition().getStatus());
        delayDto.setDelayFlage(condition.getCondition().getDelayFlage());
        return delayMngService.getDelayList(delayDto);
    }


    /**
     * 删除草稿状态的延期申请信息
     *
     * @param condition
     * @return
     */
    @ApiOperation("删除草稿状态的延期申请信息")
    @PostMapping("/deleteDelay")
    public IResponse deleteDelay(@RequestBody DelayDto delayDto) {
        return delayMngService.deleteDelay(delayDto);
    }

    /**
     * 提交延期申请和暂存
     *
     * @param condition
     * @return
     */
    @ApiOperation("提交延期申请和暂存")
    @PostMapping("/submitDelay")
    public IResponse submitDelay(@RequestBody DelayDto delayDto) {
        return delayMngService.submitDelay(delayDto);
    }

    /**
     * 编辑(查看) 延期申请id
     *
     * @param condition
     * @return
     */
    @ApiOperation("编辑(查看) 延期申请id")
    @PostMapping("/lookDelay")
    public IResponse lookDelay(@RequestBody DelayDto delayDto) {
        return delayMngService.lookDelay(delayDto);
    }

    /**
     * 申请延期申请 申请编号延期类型2-网约车归档延期默认类型可以不传
     *
     * @param condition
     * @return
     */
    @ApiOperation("提交延期申请和暂存")
    @PostMapping("/newDelay")
    public IResponse newDelay(@RequestBody DelayDto dto) {
        return delayMngService.newDelay(dto);
    }

}
